#coding:utf-8
# 判断--请求方式的封装
import requests
import json
import urllib3
urllib3.disable_warnings()

# headers = {
#     'Accept-Encoding': "gzip, deflate",
#     'Content-Type': "application/x-www-form-urlencoded",
#     'Host': "api.zxyjsc.com",
#     'Connection': "Keep-Alive",
#     'User-Agent': "okhttp/3.8.0",
#     'Accept': "*/*",
#     'cache-control': "no-cache"
#     }
# headers_json = {
#     'Accept-Encoding': "gzip, deflate",
#     'Host': "api.zxyjsc.com",
#     'Connection': "Keep-Alive",
#     'User-Agent': "okhttp/3.8.0",
#     'Content-Type': "application/json",
#     'cache-control': "no-cache",
#     }
class RunMethod:
	def post_main(self,url,data,cookies=None,headers=None):
		res = None
		if cookies !=None:	
			res = requests.post(url=url,data=data,cookies=cookies,verify=False, headers=headers)
		else:
			res = requests.post(url=url,data=data,verify=False, headers=headers)
		return res.json()

	def get_main(self,url,data=None,cookies=None,headers=None):
		res = None
		if cookies !=None:	
			res = requests.get(url=url,params=data,cookies=cookies,verify=False, headers=headers)
		else:
			res = requests.get(url=url,params=data,verify=False, headers=headers)
		return res.json()

	def put_main(self,url,data,cookies=None,headers=None):
		res = None
		if cookies !=None:	
			res = requests.put(url=url,data=data,cookies=cookies,verify=False, headers=headers)
		else:
			res = requests.put(url=url,data=data,verify=False, headers=headers)
		return res.json()

	def delete_main(self,url,data,cookies=None,headers=None):
		res = None
		if cookies !=None:	
			res = requests.delete(url=url,data=data,cookies=cookies,verify=False, headers=headers)
		else:
			res = requests.delete(url=url,data=data,verify=False, headers=headers)
		return res.json()

	def run_main(self,method,url,data=None,cookies=None,headers=None):
		res = None
		if method == 'post':
			res = self.post_main(url,data,cookies,headers)
		elif method == 'put':
			res = self.put_main(url,data,cookies,headers)
		elif method == 'delete':
			res = self.delete_main(url,data,cookies,headers)
		else:
			res = self.get_main(url,data,cookies,headers)
		return json.dumps(res,ensure_ascii=False)
		#return json.dumps(res,ensure_ascii=False,sort_keys=True,indent=2)
